#coding:utf-8
import os
import time
from common.Action import Action
from common.FuyuanwaiConf import FuyuanwaiConf
from common.MngAction import MngAction
from common.koufuApi import KoufuApi
from common.koufuShopApi import KoufuShopApi

__author__ = 'yangxianming'

from common.KoufuConf import KoufuConf
import json
import requests


def case():
    #初始化必要的参数
    fuyuanwaiConf = FuyuanwaiConf()
    action = Action()
    url = fuyuanwaiConf.testCoreDomain + "/mngWeb/mng"
    test_url = fuyuanwaiConf.testDomain + "/pointweb/point"
    script_name = os.path.basename(__file__)
    tf = True
    test_result = ""

    try:
        #appid purchaserId 查询接口
        body = {"request_id":1578902607423}
        p = {"action":action.MngAction.efuli_backend_app_list, "body":body}
        r = requests.post(url, data=json.dumps(p), headers=fuyuanwaiConf.testCoreHeader)
        r_json = r.json()
        print("这个是接口" + action.MngAction.efuli_backend_app_list + "返回的全部参数\n", r_json)

        #核心后管創建項目
        body = {"request_id":1578902607423,"projectName":"一百项目2","remark":"备注","purchaserId":"yibai1a1fc944612829a8c9427fdf032"}
        p = {"action":action.MngAction.efuli_coremng_order_project_create, "body":body}
        r = requests.post(url, data=json.dumps(p), headers=fuyuanwaiConf.testCoreHeader)
        r_json = r.json()
        print("这个是接口" + action.MngAction.efuli_coremng_order_project_create + "返回的全部参数\n", r_json)

        #核心后管創建查询
        body = {"requestId":1578902607423,"purchaserId":"yibai1a1fc944612829a8c9427fdf032"}
        p = {"action":action.MngAction.efuli_coremng_order_project_query_purchaser_id, "body":body}
        r = requests.post(url, data=json.dumps(p), headers=fuyuanwaiConf.testCoreHeader)
        r_json = r.json()
        print("这个是接口" + action.MngAction.efuli_coremng_order_project_query_purchaser_id + "返回的全部参数\n", r_json)

        #项目删除
        body = {"requestId":1578902607423,"projectId":"4fadf4f35e384857892e33dff9f7dced","appId":"welfarepoint12345678901234567890"}
        p = {"action":action.MngAction.efuli_coremng_order_project_delete_project_id, "body":body}
        r = requests.post(url, data=json.dumps(p), headers=fuyuanwaiConf.testCoreHeader)
        r_json = r.json()
        print("这个是接口" + action.MngAction.efuli_coremng_order_project_delete_project_id + "返回的全部参数\n", r_json)

        #福员外支付页面
        body = {"corpUserId":"fdd5a9413709463893d2a713e07abaca","corpId":"382aa7ec0d0143828843c0dbe88fcfe8","request_id":1560998649993}
        p ={"action":action.FywWebAction.efuli_welfarepoint_before_benefits,"body":body}
        print(test_url)
        print(p)
        r = requests.post(test_url, data=json.dumps(p), headers=fuyuanwaiConf.proHeaders)
        r_json = r.json()
        print("这个是接口" + action.FywWebAction.efuli_welfarepoint_before_benefits + "返回的全部参数\n", r_json)

        #具体判断
        # if voucherId is not None:
        #     tf = False
    except Exception as e:
        err_info = str(e).replace("'", "").replace("\"", "")
        test_result = "非预期的异常,脚本文件:" + script_name + "; 错误信息：" + err_info
        tf = -2

    #定义预期描述
    print(str(tf))
    print(test_result)
    expect_result = "返回参数ebuyCode是否是空"

    #返回测试结果 第一个参数:True or False    第二个参数测试结果描述
    return tf, [test_result, expect_result]

case()